package com.zhou.controller;

import com.zhou.service.ProcessService;
import com.zhou.utis.result.Result;
import com.zhou.vo.processVo.InsertProcessVO;
import com.zhou.vo.processVo.UpdateProcessVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhouyuyan
 */
@RestController
@RequestMapping("process")
public class ProcessController {
    @Resource
    private ProcessService processService;
    /**
     * 新增审核申请
     */
    @PostMapping("add")
    public Result add(@RequestBody InsertProcessVO vo) {
        try {
            return Result.success(processService.add(vo));
        } catch (RuntimeException e) {
            return Result.error(e.getMessage());
        }
    }
    /**
     * 一审
     */
    @PutMapping("update")
    public Result update(String processId){
        try {
            return Result.success(processService.update(processId));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }
    /**
     * 修改申请
     */
    @PutMapping("update_one")
    public Result updateOne(@RequestBody UpdateProcessVO vo){
        try {
            return Result.success(processService.updateOne(vo));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }
    /**
     * 申请查询
     */
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable("id") String processId){
        try {
            return Result.success(processService.getById(processId));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }
    /**
     * 申请分页查询
     */
    @GetMapping("getAll")
    public Result getAll(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer pageSize ){
        try {
            return Result.success(processService.getAll(page,pageSize));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }
}
